﻿#if 0
#include "FrameListAnimator.h"

#define	DELAY_TYPES	7
byte delayDivShifts[DELAY_TYPES] = {
	4,5,6,7,8,9,10 // 16, 32, 64, 128, 256, 512, 1024
};

// Μπορούμε να αποφύγουμε και το array addressing εάν αντί να έχουμε
// delay  [0,8) έχουμε απευθείας delay  { 4,5,6,7,8,9,10 }

#define	DIV_DELAY(x,d)	((x) >> delayDivShifts[d])
#define	MUL_DELAY(x,d)	((x) << delayDivShifts[d])

/*
byte i = DIV_DELAY(currTime - lastTime, anim->GetDelay());
if(i) {
	lastTime += MUL_DELAY(i, anim->GetDelay());
	while (i--) {
		// Το προηγούμενο εκτός της αύξησης του lastTime
	}
}
*/

FrameListAnimator::FrameListAnimator (void): 
	 	sprite((Sprite*) 0), 
		anim((FrameListAnimation*) 0), currFrame(0xFF) {}

void FrameListAnimator::Start(Sprite* s, FrameListAnimation* a, timestamp_t t) {
	sprite = s;
	anim = a;
	lastTime = t;
	state = ANIMATOR_RUNNING;
	std::list<frame_t> frames = a->GetFrames();
	currFrame = frames.pop_front();
	frames.push_back(currFrame);
	a->SetFrames(frames);
}

void FrameListAnimator::Progress (timestamp_t currTime) {
	while (currTime > lastTime && currTime - lastTime >= anim->GetDelay()) {

	    if (currFrame == anim->GetEndFrame())
		currFrame = anim->GetStartFrame();
	    else
		++currFrame;

	    sprite->Move(anim->GetDx(), anim->GetDy());
	    sprite->SetFrame(currFrame);
	    lastTime += anim->GetDelay();

	    if (currFrame == anim->GetEndFrame() && !anim->GetContinuous()) {
		state = ANIMATOR_FINISHED;
		NotifyStopped();
		return;
	    }
	}
}
#endif
